<?php
abstract class Controller {

    protected $layout = 'default';
    protected $title;
    protected $script;
    protected $content;
    protected $css;
    protected $stylesheet;
    protected $name;
    protected $debug;

    function __construct() {
        $this->name = strtolower(substr(get_class($this),0,-10));
        $this->loadStyle();
        logger::info('Initialisation du controleur',__FILE__,__LINE__);
    }
	
    protected function loadStyle() {
        $this->css .= Html::css('reset');
        if(is_array($this->stylesheet)) {
            foreach($this->stylesheet AS $value) {
                $this->css .= Html::css($value);
            }
        }
    }
	
    protected function merge($templatefile,$value = null) {
        if(file_exists(ROOT_DIR.DS.'templates'.DS.$templatefile.'.php')) {
            
            ob_start();
            if(is_array($value)) {
                foreach($value AS $key => $valeur) {
                    $$key = $valeur;
                }
            }
            include(ROOT_DIR.DS.'templates'.DS.$templatefile.'.php');
            $content = ob_get_contents();
            var_dump($content);
            ob_end_clean();
            return $content;
        }
    }
	
    protected function loadLayout() {
        include(ROOT_DIR.DS.'layout'.DS.$this->layout.'.php');
    }
	
    protected function loadModel() {
        if(file_exists('models'.DS.$this->name.'.php')){
            require_once('models'.DS.$this->name.'.php');
        }
    }
	
    public function __destruct() {
        if($this->sql)
            $this->loadModel();
        if(Config::read('debug') > 0)
            $this->debug = logger::display();
        $this->loadLayout();
    }
}
?>